﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class PhuCapInfo
    {
        private string _PhuCapID;

        public string PhuCapID
        {
            get { return _PhuCapID; }
            set { _PhuCapID = value; }
        }

        private string _Ten;

        public string Ten
        {
            get { return _Ten; }
            set { _Ten = value; }
        }

        private float _Luong;

        public float Luong
        {
            get { return _Luong; }
            set { _Luong = value; }
        }

        private float _HeSo;

        public float HeSo
        {
            get { return _HeSo; }
            set { _HeSo = value; }
        }

        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class PhuCapCtr
    {
        string strCnn = DBClass_FANIT82.GetConnectString();

        public void Insert(PhuCapInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@PhuCapID", Item.PhuCapID),
                new SqlParameter("@Ten", Item.Ten == null ? (object)DBNull.Value:Item.Ten),
                new SqlParameter("@Luong", Item.Luong == null ? (object)DBNull.Value:Item.Luong),
                new SqlParameter("@HeSo", Item.HeSo == null ? (object)DBNull.Value:Item.HeSo),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_PhuCap_Insert", Para);
        }

        public void Update(PhuCapInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@PhuCapID", Item.PhuCapID),
                new SqlParameter("@Ten", Item.Ten == null ? (object)DBNull.Value:Item.Ten),
                new SqlParameter("@Luong", Item.Luong == null ? (object)DBNull.Value:Item.Luong),
                new SqlParameter("@HeSo", Item.HeSo == null ? (object)DBNull.Value:Item.HeSo),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_PhuCap_Update", Para);
        }

        public void Delete(string strPhuCapID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@PhuCapID", strPhuCapID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_PhuCap_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_PhuCap_GetList");
            return Ds.Tables[0];
        }

        public PhuCapInfo GetByID(string strPhuCapID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_PhuCap_Get", new SqlParameter("PhuCapID", strPhuCapID));
            PhuCapInfo ObjPhuCap = null;
            while (dtr.Read())
            {
                ObjPhuCap = new PhuCapInfo();
                ObjPhuCap.PhuCapID = dtr["PhuCapID"].ToString();
                ObjPhuCap.Ten = dtr["Ten"].ToString();
                ObjPhuCap.Luong = (float)dtr["Luong"];
                ObjPhuCap.HeSo = (float)dtr["HeSo"];
                ObjPhuCap.Active = (bool)dtr["Active"];
            }
            return ObjPhuCap;
        }
    }
}
